const fs=require("fs");
const path=require("path");
process.stdout.write("请输入要创建的文件夹:");
var dirArr;
var dirName;
var fileName1;
var fileName2;
process.stdin.on("data",function(chunk){ 
    var chunk=chunk.toString("utf8");
    var Name=chunk.slice(0,-2);
    dirArr=Name.split(' ');
    if(dirArr[0]=="mkdir"){
        dirName=dirArr[1];
        process.stdin.emit("createDir");
    }else if(dirArr[0]=="touch"){
        fileName1=dirArr[1];
        process.stdin.emit("createFile");
    }else{      
        fileName2=dirArr[1];
        process.stdin.emit("deleteFile");
    }            
})
//创建文件夹
process.stdin.on("createDir",function(){
    fs.mkdirSync(dirName);
    console.log("文件目录创建成功！！");
    process.stdout.write("请输入要创建的的文件:");
})
//创建文件
process.stdin.on("createFile",function(){
    var filePath=path.join(__dirname,'./'+dirName+'/'+fileName1);
    fs.writeFileSync(filePath,"hello node","utf-8");
    console.log("文件创建成功！！");
    process.stdout.write("请输入要删除的文件：");
})
//删除文件
process.stdin.on("deleteFile",function(){
    var filePath=path.join(__dirname,'./'+dirName+'/'+fileName2);
    fs.unlinkSync(filePath);
    console.log("文件删除成功！！");
})
